package com.alogic.textfilter;

import com.alogic.load.Loader;
import com.alogic.textfilter.loader.HotLoader;
import com.anysoft.util.PropertiesConstants;
import com.anysoft.util.Settings;

/**
 * 工厂类
 *
 * @since 1.6.13.10 [20200827 duanyy]
 */
public class TextFilterFactory extends Loader.Manager<TextFilter>{

    /**
     * 缺省的实例
     */
    private static Loader<TextFilter> INSTANCE = null;

    /**
     * 缺省配置文件地址
     */
    protected static final String DEFAULT = "java:///com/alogic/textfilter/default.xml#" + TextFilterFactory.class.getName();

    @Override
    protected String getDefaultClass() {
        return HotLoader.class.getName();
    }

    /**
     * 获取一个缺省的Loader
     *
     * 缺省Loader的配置文件通过环境变量sda.master和sda.secondary指定
     *
     * @return Loader实例
     */
    public static Loader<TextFilter> getDefault(){
        if (INSTANCE == null){
            synchronized (TextFilterFactory.class){
                if (INSTANCE == null){
                    Settings p = Settings.get();
                    String master = PropertiesConstants.getString(p, "textfilter.master", DEFAULT);
                    String secondary = PropertiesConstants.getString(p, "textfilter.secondary", DEFAULT);
                    TextFilterFactory f = new TextFilterFactory();
                    INSTANCE = f.loadFrom(master, secondary);
                }
            }
        }
        return INSTANCE;
    }
}